<?php 
/**
*file TagModel.class.php
*文章标签类
*
*@auther houtizong
*@version 1.0
*/
defined('ACC') ||exit ('ACC Denied');

class TagModel extends Model{
	protected $table = 'tag'; 
	protected $pk = 'tag_id'; //主键

    //自动过滤 域
	protected $_field = array(
		'tag_id','tagname','art_id','addtime'
		);
		
	//自动填充
	protected $_auto = array(
            array('addtime','function','time')
		);
   //验证

/**
*根据文章发布传来的tags字段信息 转成索引数组插入tag表
*@param string $tags
*@param int $id  文章id
*@param time()  创建时间
*return  bool  / 循环insert into tag
*/
public function tagInsert($tags,$id,$addtime){
	$tags = explode(',', $tags);
	$sql = 'insert into '.$this->table.' (art_id,tagname,addtime)'.' values ';
	foreach ($tags as $v) {
		$sql .= '('. $id . ','. "'$v'" . ','. $addtime .'),';
	}
	$sql = rtrim($sql,','); //去掉尾部的,号
	return $this->db->query($sql);
}

/**
*查询总评论数  $total
*/
public function tagTotal(){
	$sql = 'select count(*) from '.$this->table;
	return $this->db->getOne($sql);
}

/**
*查询所有评论 并分页
*@param $offset 偏移量
*@param $limit 显示数 
*return array[0]
*/
public function tagList($offset=0,$limit=12){
	$sql = 'select tag_id,FROM_UNIXTIME(addtime) as addtime,art_id,tagname from '.$this->table.
	' order by art_id desc limit '. $offset.','.$limit;
	return $this->db->getAll($sql);
}






}
?>